﻿using System;
using ASP;
using HKB.Common;
using HKB.Data.Bll;
using HKB.Web;
using HKB.Web.DataHelper;
using HKB.Web.Shop;
using System;
using System.Data;
using System.Text;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

public partial class UserControls_Common_Top : System.Web.UI.UserControl
{
    private Shop _objShop = null;
    private Conn conn = new Conn();
    private string _name;
    private string _shopRootUrl = string.Empty;
    private string _currentCity = string.Empty;
    private string _selectType = string.Empty;
    private int _selectTypeID = 0;
    private string showProType = "";
    private string requestpage = "";
    private HL_NavegateBll _navegate = null;
    private Shop_Class _class = null;
    private int _rownumber = 0;
    protected DefaultProfile profile
    {
        get
        {
            return (DefaultProfile)this.Context.Profile;
        }
    }
    protected global_asax applicationInstance
    {
        get
        {
            return (global_asax)this.Context.ApplicationInstance;
        }
    }
    public Shop objShop
    {
        get
        {
            if (this._objShop == null)
            {
                this._objShop = new Shop();
            }
            return this._objShop;
        }
    }
    public string User_Name
    {
        get
        {
            Shop shop = new Shop();
            if (shop.user != null)
            {
                this._name = shop.user.UserName;
            }
            return this._name;
        }
        set
        {
            this._name = value;
        }
    }
    public string ShopRootUrl
    {
        get
        {
            string shopRootUrl;
            if (!string.IsNullOrEmpty(this._shopRootUrl))
            {
                shopRootUrl = this._shopRootUrl;
            }
            else
            {
                SiteConfigBll siteConfigBll = new SiteConfigBll();
                DataTable siteConfig = siteConfigBll.GetSiteConfig();
                this._shopRootUrl = siteConfig.Rows[0]["ShopRootUrl"].ToString();
                shopRootUrl = this._shopRootUrl;
            }
            return shopRootUrl;
        }
        set
        {
            this._shopRootUrl = value;
        }
    }
    public string CurrentCity
    {
        get
        {
            return this._currentCity;
        }
        set
        {
            this._currentCity = value;
        }
    }
    public string SelectType
    {
        get
        {
            return this._selectType;
        }
        set
        {
            this._selectType = value;
        }
    }
    public int SelectTypeID
    {
        get
        {
            return this._selectTypeID;
        }
        set
        {
            this._selectTypeID = value;
        }
    }
    public string ShowProType
    {
        get
        {
            if (base.Request.QueryString["showProType"] != null)
            {
                this.showProType = base.Request.QueryString["showProType"].ToString();
            }
            if (this.showProType != "")
            {
                this.showProType = string.Format("&showProType={0}", this.showProType);
            }
            return this.showProType;
        }
        set
        {
            this.showProType = value;
        }
    }
    protected string topwidth
    {
        get;
        set;
    }
    protected string wwidth
    {
        get;
        set;
    }
    protected string main_box_content_width
    {
        get;
        set;
    }
    protected HL_NavegateBll m_navegate
    {
        get
        {
            if (this._navegate == null)
            {
                this._navegate = new HL_NavegateBll(this.conn);
            }
            return this._navegate;
        }
    }
    protected Shop_Class m_class
    {
        get
        {
            Shop_Class @class;
            if (this._class == null)
            {
                this._class = new Shop_Class(this.conn);
                @class = this._class;
            }
            else
            {
                @class = this._class;
            }
            return @class;
        }
    }
    protected int rownumber
    {
        get
        {
            return this._rownumber;
        }
        set
        {
            this._rownumber = value;
        }
    }
    protected string ml_li_bg_class
    {
        get
        {
            string result;
            if (++this._rownumber % 2 == 1)
            {
                result = "mun_bg_r";
            }
            else
            {
                result = "mun_bg_b";
            }
            return result;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        this.GetCityDomain();
        this.requestpage = base.Request.Url.AbsolutePath.ToLower();
        if (this.requestpage == "/default.aspx" || this.requestpage.StartsWith("/tuan/"))
        {
        //    this.main_box_content_width = " style=\"width:960px;\" ";
        //    this.topwidth = "top990";
        //    this.wwidth = "w990";
        }
        else
        {
            //if (this.requestpage == "/index.aspx")
            //{
            //    this.main_box_content_width = " style=\"width:1220px;\" ";
            //    this.topwidth = "top1220";
            //    this.wwidth = "w1220";
            //}
            //else
            //{
            //    this.main_box_content_width = " style=\"width:990px;\" ";
            //    this.topwidth = "top990";
            //    this.wwidth = "w990";
            //}
        }
        if (!base.IsPostBack)
        {
            this.txtProductName.Attributes.Add("onkeypress", "KeyPress('txtProductName');");
            this.txtShopName.Attributes.Add("onkeypress", "KeyPress('txtShopName');");
            this.bind();
        }
        int num = 0;
        string text = "";
        if (this.objShop.user.CheckUserLogin())
        {
            DataTable dataTable = BLLInstance.BllShoppingCarts.GetList(" userID=" + this.objShop.user.UserID).Tables[0];
            num = dataTable.Rows.Count;
            for (int i = 0; i < dataTable.Rows.Count; i++)
            {
                DataRow dataRow = dataTable.Rows[i];
                text = text + dataRow["CartID"].ToString() + ",";
            }
        }
        if (!string.IsNullOrEmpty(text))
        {
            text = text.Substring(0, text.Length - 1);
        }
        if (num == 0)
        {
            //this.toPay.Attributes.Add("onclick", "alert('购物车中还没有商品,请刷新页面尝试！');return false;");
        }
        else
        {
            if (num > 0)
            {
                //this.toPay.Attributes.Add("onclick", "window.location.href='/setSendAndPayment.aspx?shopcartID=" + text + "';");
            }
        }
        //this.LabelShopCarNum.Text = num.ToString();
    }
    protected string main_box_menu_display(bool display_in_index)
    {
        string result;
        if (display_in_index)
        {
            if (this.requestpage != "/index.aspx")
            {
                result = " style=\"display:none;\" ";
            }
            else
            {
                result = "";
            }
        }
        else
        {
            if (this.requestpage != "/index.aspx")
            {
                result = "";
            }
            else
            {
                result = " style=\"display:none;\" ";
            }
        }
        return result;
    }
    protected void bind()
    {
        //DataTable linksAll = this.m_navegate.GetLinksAll(new string[0]);
        //this.Repeater_Navegate.DataSource = linksAll;
        //this.Repeater_Navegate.DataBind();
        //for (int i = 0; i < this.Repeater_Navegate.Items.Count; i++)
        //{
        //    HyperLink hyperLink = (HyperLink)this.Repeater_Navegate.Items[i].FindControl("hlNavegateTitle");
        //    if (hyperLink != null)
        //    {
        //        if (hyperLink.Text == "积分换购")
        //        {
        //            hyperLink.Visible = false;
        //            if (StaticFunApp.ShopConfig["ShowScore"].IsNull(new object[0]) == "1")
        //            {
        //                hyperLink.Visible = true;
        //            }
        //        }
        //    }
        //}
        //this.bindClass();
    }
    private void GetCityNameByDomain()
    {
        //string text = base.Request.Url.AbsoluteUri.Replace("http://", "");
        //string text2 = "";
        //if (text.IndexOf("." + this.ShopRootUrl) > 0)
        //{
        //    text2 = text.Substring(0, text.IndexOf("." + this.ShopRootUrl));
        //    if (text2 == "www")
        //    {
        //        this.HFSelectCity.Value = "";
        //        return;
        //    }
        //}
        //if (text2 != "")
        //{
        //    IDbDataParameter dbDataParameter = this.conn.CreateParameter("@DomainName", DbType.String, text2);
        //    DataTable dataTable = this.conn.GetDataTable("select * from dbo.CM_Domain where DomainName=@DomainName", new IDbDataParameter[]
        //    {
        //        dbDataParameter
        //    });
        //    if (dataTable != null && dataTable.Rows.Count > 0)
        //    {
        //        this.HFSelectCity.Value = dataTable.Rows[0]["DomainName"].ToString() + "|" + dataTable.Rows[0]["City"].ToString();
        //        this.ltrCurrentCity.Text = dataTable.Rows[0]["City"].ToString();
        //        this._currentCity = dataTable.Rows[0]["City"].ToString();
        //    }
        //}
        //else
        //{
        //    this.HFSelectCity.Value = "";
        //}
    }
    private void GetCityDomain()
    {
        //HoWave_Root hoWave_Root = new HoWave_Root();
        //DataTable dataTable = new Conn().GetDataTable("select DomainName,SortNumber,City,Disable \r\n                                                                          from CM_Domain  where Disable=1  order by SortNumber Desc");
        //StringBuilder stringBuilder = new StringBuilder("");
        //foreach (DataRow dataRow in dataTable.Rows)
        //{
        //    stringBuilder.Append(string.Concat(new object[]
        //    {
        //        "<a  href='http://",
        //        dataRow["DomainName"],
        //        ".",
        //        this.ShopRootUrl,
        //        "'>",
        //        dataRow["City"],
        //        "</a>"
        //    }));
        //}
        //this.ltraLLHotCity.Text = stringBuilder.ToString();
    }
    protected void btnSearchService_Click(object sender, EventArgs e)
    {
        if (this.txtProductName.Text == "输入商品名称")
        {
            this.txtProductName.Text = "";
        }
        base.Response.Redirect("~\\ProductList.aspx?productname=" + this.txtProductName.Text.Trim() + this.ShowProType);
    }
    protected void btnSearchShop_Click(object sender, EventArgs e)
    {
        if (this.txtShopName.Text == "输入店铺名称")
        {
            this.txtShopName.Text = "";
        }
        base.Response.Redirect("~\\Search_Shop.aspx?ShopName=" + this.txtShopName.Text + this.ShowProType);
    }
    private void bindClass()
    {
        //DataTable classListByParnetID = this.m_class.GetClassListByParnetID(4, 0, new bool[0]);
        //this.Repeater_product_class.DataSource = classListByParnetID;
        //this.Repeater_product_class.DataBind();
        //this.Repeater_product_ElseClass.DataSource = this.m_class.GetClassListByParnetID(20, 4, 0, new bool[0]);
        //this.Repeater_product_ElseClass.DataBind();
    }
    public string GetShortString(object obj, int n)
    {
        string text = (obj != null) ? obj.ToString() : "";
        string text2 = string.Empty;
        string result;
        if (Encoding.Default.GetByteCount(text) <= n)
        {
            result = text;
        }
        else
        {
            int num = 0;
            char[] array = text.ToCharArray();
            for (int i = 0; i < array.Length; i++)
            {
                if (array[i] >= '一' && array[i] <= '龥')
                {
                    text2 += array[i];
                    num += 2;
                }
                else
                {
                    text2 += array[i];
                    num++;
                }
                if (num >= n)
                {
                    break;
                }
            }
            result = text2 + "...";
        }
        return result;
    }
    protected void Repeater_product_class_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater repeater = (Repeater)e.Item.FindControl("Repeater_product_smallclass");
            repeater.ItemDataBound += new RepeaterItemEventHandler(this.Repeater_product_smallclass_ItemDataBound);
            DataRowView dataRowView = (DataRowView)e.Item.DataItem;
            int parentID = Convert.ToInt32(dataRowView["ClassID"]);
            DataTable classListByParnetID = this.m_class.GetClassListByParnetID(6, parentID, new bool[0]);
            repeater.DataSource = classListByParnetID;
            repeater.DataBind();
        }
    }
    protected void Repeater_product_smallclass_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            try
            {
                Repeater repeater = (Repeater)e.Item.FindControl("Repeater_product");
                DataRowView dataRowView = (DataRowView)e.Item.DataItem;
                int parentID = Convert.ToInt32(dataRowView["ClassID"]);
                DataTable classListByParnetID = this.m_class.GetClassListByParnetID(20, parentID, new bool[0]);
                repeater.DataSource = classListByParnetID;
                repeater.DataBind();
            }
            catch (Exception)
            {
            }
        }
    }
    protected void Repeater_ElseClass_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            try
            {
                Repeater repeater = (Repeater)e.Item.FindControl("Repeater_product");
                DataRowView dataRowView = (DataRowView)e.Item.DataItem;
                int parentID = Convert.ToInt32(dataRowView["ClassID"]);
                DataTable classListByParnetID = this.m_class.GetClassListByParnetID(20, parentID, new bool[0]);
                repeater.DataSource = classListByParnetID;
                repeater.DataBind();
            }
            catch (Exception)
            {
            }
        }
    }
}
